import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

/**
 * 排序方法:sort
 */
public class Demo04 {

  public static void main(String[] args) {
    int[] arr = {9, 8, 7, 6, 5, 4, 3, 2, 1};//定义数组

    //随机填充数组
    arr = new int[9];
    Random r = new Random();
    for (int i = 0; i < arr.length; i++) {
      arr[i] = r.nextInt(100);
    }

//    arr = new int[]{1,2,3,4,5,6,7,8,9};

    System.out.println("排序前的原始数组:\t" + Arrays.toString(arr));
    Arrays.sort(arr);

    System.out.println("排序后的原始数组:\t" + Arrays.toString(arr));


    Integer[] arr1 = {5,2,6,1,9,3};
    System.out.println("排序前的原始数组:\t" + Arrays.toString(arr1));
    Arrays.sort(arr1,
        new Comparator<Integer>() {

          @Override
          public int compare(Integer o1, Integer o2) {
            return o2-o1;
          }
        });
    System.out.println("降序排序后的原始数组:\t" + Arrays.toString(arr1));
    Arrays.sort(arr1,(o1,o2)->o1-o2);//jdk1.8+ lambda表达式
    System.out.println("升序排序后的原始数组:\t" + Arrays.toString(arr1));
    Arrays.sort(arr1,(o1,o2)->r.nextInt());
    System.out.println("乱序排序后的原始数组:\t" + Arrays.toString(arr1));

    String[][] ss = new String[9][];
    ss[0] = new String[1];
    ss[0][0] = "1*1=1";
    ss[1] = new String[2];
    ss[1][0] = "1*2=2";
//    ss[1] = new String[2];
    ss[1][1] = "2*2=4";
  }
}


